<?php
class RackProducts extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Organizations the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'rack_products';
	}
	
	public function relations()
	{
		return array(
			'product'=>array(self::BELONGS_TO, 'Products', 'product_ID'),
			'rack'=>array(self::BELONGS_TO, 'Racks', 'rack_ID'),
		);
	}
	
	public function getCurMinPrice($product_ID)
	{
		$connection = Yii::app()->db;
		$sql='select min(current_price) from '.RackProducts::model()->tableName().' where product_ID='.$product_ID.' and date=CURDATE()';
		$command = $connection->createCommand($sql);
		$dataReader = $command->query();
		foreach($dataReader as $row)
		{
			return $row['min(current_price)'];
		}
	}
}
?>
